<template>
    <div class="tab-bar-item" @click="tabBarItem">
        <!-- <img src="../../assets/img/tabbar/index.svg" alt="index">
        <div>首頁</div> -->

        <!-- 用插槽代替上面的结构内容 -->
        <div v-if="!isActive">
            <slot name="item-icon"></slot>
        </div>
        <div v-else="isActive">
            <slot name="item-icon-active"></slot>
        </div>
        <!-- <div :class="{active:isActive}"> -->

        <div :style="activeStyle">    
            <slot name="item-text"></slot>
        </div>
    </div>
</template>

<script>
export default {
    name:'TabBarItem',
    data(){
        return {
            //isActive:true
        }
    },
    computed:{
        isActive(){
            //$route: 哪一个路由处于活跃就是哪一个路由对象
            return this.$route.path.indexOf(this.path) != -1  //不等于 -1 就代表当前点击的路由与传递的路由是相等的
        },
        activeStyle(){
            return this.isActive ? {color:this.activeColor} : {}
        }
    },
    props:{
        path:{
            type: String,
        },
        activeColor: {
            type: String,
            default: 'red'
        }
    },
    methods:{
        tabBarItem(){
           this.$router.push(this.path)
        }
    }
}
</script>

<style>
.tab-bar-item {
    flex: 1;
    text-align: center;
    height: 49px;
    font-size:14px;
}
.tab-bar-item img {
    width: 24px;
    height: 24px;
    margin-top:3px;
    vertical-align: middle;
    margin-bottom: 2px;
}
/* .active{
    color:red
} */
</style>